package com.wind.taobao.api.sns.convert
{
	import com.wind.taobao.api.sns.model.Picture;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * SNS Picture转换器
	 * @author fxy
	 *
	 */
	public class PictureConvert
	{
		/**
		 * 转换Picture集合
		 */
		public static function convertPictures(value:Object, type:String="json"):ArrayCollection
		{
			var pictures:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							pictures.addItem(convertPicture((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return pictures;
		}

		/**
		 * 转换Picture
		 */
		public static function convertPicture(value:Object, type:String="json"):Picture
		{
			var picture:Picture=new Picture();
			if (value == null)
				return picture;
			if (type == TaobaoConstants.XML)
			{
				picture=convertXMLToPicture(XML(value), picture);
			}
			else
			{
				picture=convertJSONToPicture(value, picture);
			}
			return picture;
		}

		/**
		 * JSON转换为Picture
		 */
		private static function convertJSONToPicture(json:Object, picture:Picture):Picture
		{
			if (json.hasOwnProperty(TaobaoConstants.PICTURE_ID))
			{
				picture.picture_id=json[TaobaoConstants.PICTURE_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.PICTURE_CATEGORY_ID))
			{
				picture.picture_category_id=json[TaobaoConstants.PICTURE_CATEGORY_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.PICTURE_PATH))
			{
				picture.picture_path=json[TaobaoConstants.PICTURE_PATH];
			}
			if (json.hasOwnProperty(TaobaoConstants.SIZES))
			{
				picture.sizes=json[TaobaoConstants.SIZES];
			}
			if (json.hasOwnProperty(TaobaoConstants.PIXEL))
			{
				picture.pixel=json[TaobaoConstants.PIXEL];
			}
			if (json.hasOwnProperty(TaobaoConstants.STATUS))
			{
				picture.status=json[TaobaoConstants.STATUS];
			}
			if (json.hasOwnProperty(TaobaoConstants.DELETED))
			{
				picture.deleted=json[TaobaoConstants.DELETED];
			}
			if (json.hasOwnProperty(TaobaoConstants.CREATED))
			{
				picture.created=json[TaobaoConstants.CREATED];
			}
			if (json.hasOwnProperty(TaobaoConstants.MODIFIED))
			{
				picture.modified=json[TaobaoConstants.MODIFIED];
			}
			return picture;
		}

		/**
		 * XML转换为Picture
		 */
		private static function convertXMLToPicture(value:XML, picture:Picture):Picture
		{
			return picture;
		}

	}
}